<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    function foo() {
        console.log(this.a);
    }

    var a = 2;
    foo();//2
</script>


<script>

    function foo(){
        console.log(this.a)
    }

    var obj = {
        a:2,
        foo: foo,
    }

    var bar = obj.foo;
    var a = "oops"
    bar();

</script>

</html>